var groupAnagrams = function (strs) {
  if (strs.length === 1 && strs[0] === "") return [""];
  const curArr = new Map();
  const resArr = [];
  for (let i = 0; i < strs.length; i++) {
    let curSortStr = strs[i].split("").sort().join("");
    if (curArr.has(curSortStr)) {
      curArr.set(curSortStr, [...curArr.get(curSortStr), strs[i]]);
    } else {
      curArr.set(curSortStr, [strs[i]]);
    }
  }
  console.log(curArr);
  for (let [key, value] of curArr) {
    console.log(key, value);
    resArr.push(value);
  }
  console.log(resArr);
};

groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]);
